function decode(msg) {
    var msgBytes = msg.msgBytes;
    var funcode = parseInt(msgBytes.slice(0, 2), 16);
    var value = parseInt(msgBytes.slice(2, 4), 16);
    var resultMap = {};
    var serviceData = {};
    if (funcode === 1) {
        resultMap["serviceId"] = 'LightnessDataReport';
        serviceData['light'] = value
    } else if (funcode === 2) {
        resultMap['serviceId'] = 'PowerDataReport';
        serviceData['power'] = value
    } else {
        resultMap['serviceId'] = '';
        serviceData['error'] = 'error'
    }
    resultMap['serviceData'] = serviceData;
    return resultMap
}

function encode(msg) {
    var serviceId = msg.serviceId;
    var resultMap = {};
    if (serviceId === 'LightnessDataReportResp') {
        resultMap['dataPayload'] = '01'
    } else if (serviceId === 'PowerDataReportResp') {
        resultMap['dataPayload'] = '02'
    } else if (serviceId === 'SetRunningStatus') {
        var r = msg.serviceDataMap['status'].toString(16);
        if (r.length == 1) {
            r = "0" + r
        }
        resultMap['dataPayload'] = r
    } else {
        resultMap['dataPayload'] = null
    }
    resultMap['dataType'] = 'hex';
    return resultMap
}



{
    "lang":"Js",
    "decoder":"",
    "encoder": "",
    "services": [
        {
            "serviceId": "LightnessDataReport",
            "respServiceId": "LightnessDataReportResp"
        }, {
            "serviceId": "PowerDataReport",
            "respServiceId": "PowerDataReportResp"
        }
    ]
}
{
    "data":{
        <#assign data=request.body.data>
        <#assign instanceid=request.header.instanceid>
        <#assign ts=request.header.ts>
        <#assign nativeid=request.header.nativeid>
        "instanceid": "${instanceid}",
        "nativeid": "${nativeid}",
        "data": [{
            "type":"STRING",
            "length":"2",
            "value":"7878"
        },{
            "type":"BYTE",
            "length":"1",
            "value":"${data['length']}"
        },{
            "type":"BYTE",
            "length":"1",
            "value":"${data['cmdId']}"
        },{
            "type":"BYTE",
            "length":"1",
            "value":"${data['instructionLength']}"
        },{
            "type":"DWORD",
            "length":"4",
            "value":"${data['serverFlag']}"
        },{
            "type":"BYTE[n]",
            "length":"n",
            "value":"${data['instruction']}"
        },{
            "type":"WORD",
            "length":"2",
            "value":"${data['reserve']}"
        },{
            "type":"WORD",
            "length":"2",
            "value":"${data['serialNumber']}"
        },{
            "type":"WORD",
            "length":"2",
            "value":"${data['crcNumber']}"
        },{
            "type":"STRING",
            "length":"2",
            "value":"0D0A"
        }]
}
}